"""
知识库文件评论相关数据模型
"""
from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field  # pyright: ignore[reportMissingImports]
from bson import ObjectId  # pyright: ignore[reportMissingImports]
from app.models.base import PyObjectId


class KnowledgeComment(BaseModel):
    """知识库文件评论模型"""
    id: Optional[PyObjectId] = Field(default=None, alias="_id")
    file_id: PyObjectId = Field(..., description="文件ID")
    user_id: PyObjectId = Field(..., description="评论者ID")
    content: str = Field(..., description="评论内容")
    parent_id: Optional[PyObjectId] = Field(default=None, description="父评论ID（回复）")
    created_at: datetime = Field(default_factory=datetime.utcnow, description="创建时间")
    updated_at: datetime = Field(default_factory=datetime.utcnow, description="更新时间")

    class Config:
        populate_by_name = True
        arbitrary_types_allowed = True
        json_encoders = {
            ObjectId: str,
            datetime: lambda v: v.isoformat()
        }

